package com.hisysteTopet.hisystepet.mapper.provider;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.hisysteTopet.hisystepet.bean.Pet;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.stereotype.Repository;

public class updatePetMessage extends SQL{

    // 动态sql，比xml好用，xml太烦了，后期学习，维修老项目还要用到
    public String updatePetMessage(Pet pet) {
        return new SQL(){{
            UPDATE("pet");
            if(pet.getPetIntroduce() != null) {
                SET("pet_introduce = #{petIntroduce}");
            }
            if(pet.getPetName() != null) {
                SET("pet_name = #{petName}");
            }
            if(pet.getPetVariety() != null) {
                SET("pet_variety = #{petVariety}");
            }
            if(pet.getPetPrice() != null) {
                SET("pet_price = #{petPrice}");
            }

            WHERE("pet_id = #{petId}");

        }}.toString();
    }

}
